<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script src="./js/global.js"></script>
    <script src="./js/config.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>菜单名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title"  required="" lay-verify="required" autocomplete="off" class="layui-input"></div>

            </div>
            <div class="layui-form-item">
                <label for="url" class="layui-form-label">
                    <span class="x-red">*</span>路由</label>
                <div class="layui-input-inline">
                    <input type="text" id="url" name="url"  required="" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span> 必填，模块格式：模块名/控制器名/方法名，插件直接设置：system/plugins/run，请留意大小写
                </div>
            </div>

            <div class="layui-form-item">
                <label for="hraf" class="layui-form-label">
                    <span class="x-red"></span>跳转链接</label>
                <div class="layui-input-inline">
                    <input type="text" id="hraf" name="hraf" placeholder="例如：index.html"   autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span> 仅限于二级菜单有跳转链接可打开页面
                </div>
            </div>

            <div class="layui-form-item">
                <label for="module" class="layui-form-label">
                    <span class="x-red">*</span>所属模块</label>
                <div class="layui-input-inline">
                    <select id="module" name="module" class="valid">


                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">后台导航</label>
                <div class="layui-input-block">
                    <input type="radio" name="nav" value="1" title="是" id="radio1">
                    <input type="radio" name="nav" value="0" title="否" id="radio2">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span> 是否显示为后台导航,仅仅一二菜单可显示后台导航
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="开启" id="sta1">
                    <input type="radio" name="status" value="0" title="关闭" id="sta2">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">修改</button></div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','request'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        var request = layui.request;
        var adminToken = localStorage.getItem("adminToken");

        //获得get参数
        var $_GET = (function(){
            var url = window.document.location.href.toString();
            var u = url.split("?");
            if(typeof(u[1]) == "string"){
                u = u[1].split("&");
                var get = {};
                for(var i in u){
                    var j = u[i].split("=");
                    get[j[0]] = j[1];
                }
                return get;
            } else {
                return {};
            }
        })();

        //获得本条信息
        request.ajax(requestUri+'/admin/system/menu/getmenu', 'get', 'json', {
            'token': adminToken,
            'id' : $_GET['id']
        }, function (req) {
            if(req.code == 1000){
                $('#title').val(req.data.title);   //菜单名称
                $('#url').val(req.data.url);       //链接地址
                $('#hraf').val(req.data.hraf);       //链接地址
                if(req.data.nav == 1){
                    $("#radio1").attr("checked", true);
                }
                if(req.data.nav == 0){
                    $("#radio2").attr("checked", true);
                }
                if(req.data.status == 1){
                    $("#sta1").attr("checked", true);
                }
                if(req.data.status == 0){
                    $("#sta2").attr("checked", true);
                }
                form.render(); //更新全部
                var module = req.data.module;

                //获得所有模块
                request.ajax(requestUri+'/admin/system/module/getmoduleconfig', 'get', 'json', {
                    'token': adminToken,
                }, function (re) {
                    if(re.code == 1000){
                        var option = '';
                        $.each(re.data,function(i,item){
                            if(item == module){
                                option += "<option value='"+item+"' selected='selected'>"+i+"</option>";
                            }else {
                                option += "<option value='"+item+"'>"+i+"</option>";
                            }
                        });
                        $('#module').append(option);　　// 给select节点追加
                        form.render('select')
                    }
                });
            }
        },function () {
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                //发异步，把数据提交给php
                request.ajax(requestUri+'/admin/system/menu/menuedit', 'get', 'json', {
                    'token': adminToken,
                    'data' : data.field,
                    'id' : $_GET['id']
                }, function (req) {
                    if(req.data.status == 1){
                        layer.alert("修改成功", {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                        });
                    }
                },function (req) {
                    layer.msg('不可修改');
                });
                return false;
            });
    });
</script>

</body>

</html>